package com.dynamic.mybatis.core.datasource;

import java.util.Map;
import java.util.Objects;

/**
 * @Description
 * @Author xs
 * @Date 2022/11/1 13:15
 */
public class DataSourceAttributesKey {

    //逻辑删除字段名
    public static final String logic_delete_column_key = "logicDelete";
    public static final String logic_delete_column_value = "logic_delete";
    //被逻辑删除值
    public static final String logic_delete_value_key = "logicDeleteValue";
    public static final String logic_delete_value = "1";
    //未被逻辑删除值
    public static final String logic_not_delete_value_key = "logicNotDeleteValue";
    public static final String logic_not_delete_value = "0";
    //创建人字段
    public static final String create_by_column_key = "createBy";
    public static final String create_by_column_value = "create_by";
    //创建时间字段
    public static final String create_time_column_key = "createTime";
    public static final String create_time_column_value = "create_time";
    //修改人字段
    public static final String updater_column_key = "updateBy";
    public static final String updater_column_value = "update_by";
    //修改时间字段
    public static final String update_time_column_key = "updateTime";
    public static final String update_time_column_value = "update_time";

    public static void setAttributes(Map<Object,Object> attrs,String logicDeleteColumn,String logicDeleteValue,String logicNotDeleteValue){
        attrs.put(logic_delete_column_key,logicDeleteColumn);
        attrs.put(logic_delete_value_key,logicDeleteValue);
        attrs.put(logic_not_delete_value_key,logicNotDeleteValue);
    }

    public static void setAttributes(Map<Object,Object> attrs,String createByColumn,String createTimeColumn,String updateByColumn,String updateTimeColumn){
        attrs.put(logic_delete_column_key,createByColumn);
        attrs.put(logic_delete_value_key,createTimeColumn);
        attrs.put(logic_not_delete_value_key,updateByColumn);
        attrs.put(logic_delete_column_key,updateTimeColumn);
    }

    public static void setAttributes(Map<Object,Object> attrs,String createByColumn,String createTimeColumn,String updateByColumn,String updateTimeColumn,String logicDeleteColumn,String logicDeleteValue,String logicNotDeleteValue){
        setAttributes(attrs,createByColumn,createTimeColumn,updateByColumn,updateTimeColumn);
        setAttributes(attrs,logicDeleteColumn,logicDeleteValue,logicNotDeleteValue);
    }


    public static boolean hasLogicDelete(String column,Map<Object,Object> attrs){
        return Objects.equals(column,attrs.get(logic_delete_column_key));
    }

    public static String getLogicDeleteValue(Map<Object,Object> attrs){
        return Objects.toString(attrs.get(logic_delete_value_key),"");
    }
    public static String getLogicNotDeleteValue(Map<Object,Object> attrs){
        return Objects.toString(attrs.get(logic_not_delete_value_key),"");
    }
    public static boolean hasCreateBy(String column,Map<Object,Object> attrs) {
        return Objects.equals(column,attrs.get(create_by_column_key));
    }

    public static boolean hasCreateTime(String column,Map<Object,Object> attrs) {
        return Objects.equals(column,attrs.get(create_time_column_key));
    }
    public static boolean hasUpdateBy(String column,Map<Object,Object> attrs) {
        return Objects.equals(column,attrs.get(updater_column_key));
    }

    public static boolean hasUpdateTime(String column,Map<Object,Object> attrs) {
        return Objects.equals(column,attrs.get(update_time_column_key));
    }
}